// ua解析
export const uaParse = e => {
  let outputer = ''
  if (e.match(/MSIE\s([^\s|]+)/gi)) {
    outputer = `<span class="ua_ie">Internet Explorer | ${e.match(/MSIE\s([^\s|]+)/gi)[0].replace('MSIE', '').split('.')[0]}`
  } else if (e.match(/FireFox\/([^\s]+)/ig)) {
    const r1 = e.match(/FireFox\/([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_firefox">Mozilla FireFox | ${r1[1]}`
  } else if (e.match(/Maxthon([\d]*)\/([^\s]+)/ig)) {
    outputer = '<span class="ua_maxthon">Maxthon'
  } else if (e.match(/UBrowser([\d]*)\/([^\s]+)/ig)) {
    const r1 = e.match(/UBrowser([\d]*)\/([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_ucweb">UCBrowser | ${r1[1]}`
  } else if (e.match(/MetaSr/ig)) {
    outputer = '<span class="ua_sogou">搜狗浏览器'
  } else if (e.match(/2345Explorer/ig)) {
    outputer = '<span class="ua_2345explorer">2345王牌浏览器'
  } else if (e.match(/2345chrome/ig)) {
    outputer = '<span class="ua_2345chrome">2345加速浏览器'
  } else if (e.match(/LBBROWSER/ig)) {
    outputer = '<span class="ua_lbbrowser">猎豹安全浏览器'
  } else if (e.match(/MicroMessenger\/([^\s]+)/ig)) {
    const r1 = e.match(/MicroMessenger\/([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_qq">微信 | ${r1[1].split('/')[0]}`
  } else if (e.match(/QQBrowser\/([^\s]+)/ig)) {
    const r1 = e.match(/QQBrowser\/([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_qq">QQ浏览器 | ${r1[1].split('/')[0]}`
  } else if (e.match(/QQ\/([^\s]+)/ig)) {
    const r1 = e.match(/QQ\/([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_qq">QQ浏览器 | ${r1[1].split('/')[0]}`
  } else if (e.match(/MiuiBrowser\/([^\s]+)/ig)) {
    const r1 = e.match(/MiuiBrowser\/([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_mi">Miui浏览器 | ${r1[1].split('/')[0]}`
  } else if (e.match(/Chrome([\d]*)\/([^\s]+)/ig)) {
    const r1 = e.match(/Chrome([\d]*)\/([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_chrome">Chrome | ${r1[1].split('.')[0]}`
  } else if (e.match(/safari\/([^\s]+)/ig)) {
    const r1 = e.match(/safari\/([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_apple">Apple Safari | ${r1[1]}`
  } else if (e.match(/Opera[\s|\/]([^\s]+)/ig)) {
    const r1 = e.match(/Opera[\s|\/]([^\s]+)/ig)[0].split('/')
    outputer = `<span class="ua_opera">Opera | ${r1[1]}`
  } else if (e.match(/Trident\/7.0/gi)) {
    outputer = `<span class="ua_ie">Internet Explorer 11`
  } else {
    outputer = '<span class="ua_other">其它浏览器'
  }
  return `${outputer}</span>`
}

// os解析
export const osParse = e => {
  let os = ''
  if (e.match(/win/ig)) {
    if (e.match(/nt 5.1/ig)) {
      os = '<span class="os_xp">Windows XP'
    } else if (e.match(/nt 6.1/ig)) {
      os = '<span class="os_7">Windows 7'
    } else if (e.match(/nt 6.2/ig)) {
      os = '<span class="os_8">Windows 8'
    } else if (e.match(/nt 6.3/ig)) {
      os = '<span class="os_8_1">Windows 8.1'
    } else if (e.match(/nt 10.0/ig)) {
      os = '<span class="os_8_1">Windows 10'
    } else if (e.match(/nt 6.0/ig)) {
      os = '<span class="os_vista">Windows Vista'
    } else if (e.match(/nt 5/ig)) {
      os = '<span class="os_2000">Windows 2000'
    } else {
      os = '<span class="os_windows">Windows'
    }
  } else if (e.match(/android/ig)) {
    os = '<span class="os_android">Android'
  } else if (e.match(/ubuntu/ig)) {
    os = '<span class="os_ubuntu">Ubuntu'
  } else if (e.match(/linux/ig)) {
    os = '<span class="os_linux">Linux'
  } else if (e.match(/iphone/ig)) {
    os = '<span class="os_mac">iPhone OS'
  } else if (e.match(/mac/ig)) {
    os = '<span class="os_mac">Mac OS X'
  } else if (e.match(/unix/ig)) {
    os = '<span class="os_unix">Unix'
  } else {
    os = '<span class="os_other">Other'
  }
  return `${os}</span>`
}
